package com.gxa.javaserver.socket;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

/**
 * @author:Teacher黄
 * @date:Created at 2020/06/16
 */
public class Client2 {
    public static void main(String[] args) throws IOException {
        // 端口
        Integer port = 9527;
        // ip地址
        String ipAddress = "127.0.0.1";
        // 创建socket对象
        Socket socket = new Socket(ipAddress, port);
        // 准备输入输出流
        // 输出流的包装
        DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
        // 输入流的包装
        DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
        // 发送消息
        dataOutputStream.writeUTF("我是石榴姐!");
        // 接收消息
        String msg = dataInputStream.readUTF();
        System.out.println("服务端:"+msg);

        // 释放资源
        dataInputStream.close();
        dataOutputStream.close();
        socket.close();
    }
}
